package eproject.mm.com.projectsupervision.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import cn.carbs.android.segmentcontrolview.library.SegmentControlView;
import eproject.mm.com.projectsupervision.R;
import eproject.mm.com.projectsupervision.adapter.BaseFragmentPagerAdapter;
import eproject.mm.com.projectsupervision.adapter.ProblemFragmentPagerAdapter;
import eproject.mm.com.projectsupervision.fragment.BaseFragment;
import eproject.mm.com.projectsupervision.fragment.ProblemFragment;
import eproject.mm.com.projectsupervision.widget.IconFontTextview;

public class ProblemListActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private ArrayList<View> vList;
    private SegmentControlView topTab;

    private List<ProblemFragment> fragmentList;
    private ProblemFragmentPagerAdapter problemFragmentPagerAdapter;

    IconFontTextview iftv_back;

    String type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_problem_list);

        Intent intent = getIntent();
        Bundle bundleFragment = intent.getExtras();
        type = bundleFragment.getString("type");

        initView();

        iftv_back = (IconFontTextview)findViewById(R.id.iftv_back);

        fragmentList = new ArrayList<ProblemFragment>();
        ProblemFragment problemFragment01 = new ProblemFragment();
        ProblemFragment problemFragment02 = new ProblemFragment();
        ProblemFragment problemFragment03 = new ProblemFragment();
        ProblemFragment problemFragment04 = new ProblemFragment();

        Bundle bundle1 = new Bundle();
        bundle1.putString("type", "1");
        problemFragment01.setArguments(bundle1);

        Bundle bundle2 = new Bundle();
        bundle2.putString("type", "2");
        problemFragment02.setArguments(bundle2);

        Bundle bundle3 = new Bundle();
        bundle3.putString("type", "3");
        problemFragment03.setArguments(bundle3);

        Bundle bundle4 = new Bundle();
        bundle4.putString("type", "0");
        problemFragment04.setArguments(bundle4);

        fragmentList.add(problemFragment01);
        fragmentList.add(problemFragment02);
        fragmentList.add(problemFragment03);
        fragmentList.add(problemFragment04);

        topTab = (SegmentControlView)findViewById(R.id.topTab);
        viewPager = (ViewPager) findViewById(R.id.vp_problem);
        viewPager.setOffscreenPageLimit(3);

        FragmentManager fm = getSupportFragmentManager();
        problemFragmentPagerAdapter = new ProblemFragmentPagerAdapter(fm, fragmentList);
        viewPager.setAdapter(problemFragmentPagerAdapter);

        topTab.setOnSegmentChangedListener(new SegmentControlView.OnSegmentChangedListener() {
            @Override
            public void onSegmentChanged(int newSelectedIndex) {
                viewPager.setCurrentItem(newSelectedIndex, false);
            }
        });
        topTab.setViewPager(viewPager);

        if(type.equals("0")){
            viewPager.setCurrentItem(3);
        }else {
            viewPager.setCurrentItem(0);
        }

        iftv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private void initView(){

    }

}
